package com.sqx.modules.orders.controller.app;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.orders.entity.dto.DramaPointPayDto;
import com.sqx.modules.orders.entity.dto.PayOrdersDto;
import com.sqx.modules.orders.service.OrdersService;
import com.sqx.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * 订单信息
 *
 * @author liyuan
 * @since 2021-07-17
 */
@RestController
@Api(value = "订单信息", tags = {"订单信息"})
@RequestMapping(value = "/app/order")
@Slf4j
public class AppOrdersController extends AbstractController {

    @Autowired
    private OrdersService ordersService;

    /**
     * 生成商品订单
     *
     * @param courseId
     * @param userId
     * @return
     */
    @Login
    @GetMapping("/insertCourseOrders")
    @ApiOperation("生成商品订单")
    public Result insertCourseOrders(Long courseId,Long courseDetailsId, @RequestAttribute("userId") Long userId) {
        return ordersService.insertCourseOrders(courseId, courseDetailsId,userId);
    }

    @Login
    @GetMapping("/insertVipOrders")
    @ApiOperation("生成会员订单")
    public Result insertVipOrders(@ApiParam("会员详情信息") Long vipDetailsId,@ApiParam("内购id") String purchaseId, @RequestAttribute("userId") Long userId) {
        return ordersService.insertVipOrders(vipDetailsId,purchaseId, userId);
    }

    @Login
    @PostMapping("/payOrders")
    @ApiOperation("支付订单")
    public Result payOrders(@RequestBody PayOrdersDto payOrdersDto){
        return ordersService.payMoney(payOrdersDto.getOrderId());
    }

    @Login
    @GetMapping("/refundOrder")
    @ApiOperation("退款订单")
    public Result refundOrder(Long orderId, String refundContent) {
        return ordersService.refundOrder(orderId, refundContent);
    }

    @Login
    @GetMapping("/selectOrderByUserId")
    @ApiOperation("我的订单")
    public Result selectOrderByUserId(Integer page, Integer limit, @RequestAttribute("userId") Long userId) {
        return ordersService.selectOrderByUserId(page, limit, userId);
    }

    /**
     * 弃用
     * @param page
     * @param limit
     * @param userId
     * @return
     */
    @Login
    @GetMapping("/consumeRecords")
    @ApiOperation("消费记录")
    public Result consumeRecords(Integer page, Integer limit, @RequestAttribute("userId") Long userId){
        return ordersService.consumeRecords(page, limit, userId);
    }


    //购买剧点，买赠，充值
    @Login
    @GetMapping("/topUpPayClassify")
    @ApiOperation("生成充值剧点订单")
    public Result topUpPayClassify(@ApiParam("剧点id")Integer classifyId,@RequestAttribute("userId")Long userId){
        return ordersService.topUpPayClassify(classifyId,userId);
    }


    @Login
    @GetMapping("/selDramaPoint")
    @ApiOperation("查询用户剧点详情记录列表")
    public Result selDramaPoint(@ApiParam("页")Integer page,@ApiParam("条数")Integer limit,@RequestAttribute("userId")Long userId){
        return ordersService.selDramaPoint(page,limit,userId);
    }

    /**
     * 剧点支付(生成订单编号，扣减剧点，记录剧点消费详情)
     * @return
     */
    @Login
    @PostMapping("/dramaPointPay")
    @ApiOperation("剧点支付")
    public Result dramaPointPay(@RequestAttribute Long userId,@RequestBody DramaPointPayDto dramaPointPayDto){
        return ordersService.dramaPointPay(userId,dramaPointPayDto);
    }


    @Login
    @GetMapping("/selectDramBalance")
    @ApiOperation("查询用户剧点余额")
    public Result selectDramBalance(@RequestAttribute("userId") Long userId){
        return ordersService.selectDramBalance(userId);
    }

    @Login
    @GetMapping("/rechargeBalance")
    @ApiOperation("充值余额记录查询")
    //todo 充值余额记录查询
    public Result rechargeBalance(@RequestAttribute("userId") Long userId,Integer page,Integer limit){
        return ordersService.rechargeBalance(userId,page,limit);
    }


}
